home *** CD-ROM | disk | FTP | other *** search
/ Windows 95 API Bible / Windows 95 API Bible 3 Disc Set.iso / Win32 API Bible Book 3 of 3 / CHAPTE11 / GETGAIN / PHONE.C < prev    next >
C/C++ Source or Header  |  1996-04-28  |  22KB  |  648 lines

  1. #include <windows.h> 
  2. #include <windowsx.h> 
  3. #include "phone.h" 
  4. #include "tapi.h"
  5.  
  6. #define BUFSIZE 256
  7. #define APIHIVERSION     0x00010028    /* 1.40 */
  8. #define APILOWVERSION    0x00010000    /* 1.0 */
  9. #define EXTHIVERSION     0x00010005    /* 1.5 */
  10. #define EXTLOWVERSION    0x00000009    /* 0.9 */ 
  11. #define MAX_PHONE        2
  12. #define OWNER            0
  13. #define MONITOR        1
  14.  
  15. LPCTSTR lpszAppName = "phoneGetGain";
  16. LPCTSTR lpszTitle   = "phoneGetGain"; 
  17.  
  18.  
  19. #if defined (WIN32)
  20.     #define IS_WIN32 TRUE
  21. #else
  22.     #define IS_WIN32 FALSE
  23. #endif
  24.  
  25. #define IS_NT      IS_WIN32 && (BOOL)(GetVersion() < 0x80000000)
  26. #define IS_WIN32S  IS_WIN32 && (BOOL)(!(IS_NT) && (LOBYTE(LOWORD(GetVersion()))<4))
  27. #define IS_WIN95   (BOOL)(!(IS_NT) && !(IS_WIN32S)) && IS_WIN32
  28.  
  29. HINSTANCE hInst;   // current instance
  30. HWND hWnd;         // parent window handle
  31. HWND hListWnd;     // listbox
  32. HDC  hdc;
  33. TEXTMETRIC  tm ;
  34.  
  35. BOOL RegisterWin95( CONST WNDCLASS* lpwc );
  36.  
  37.  
  38. int APIENTRY WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance,
  39.                       LPTSTR lpCmdLine, int nCmdShow)
  40. {
  41.    MSG      msg;
  42.    WNDCLASS wc;
  43.  
  44.    wc.style         = CS_HREDRAW | CS_VREDRAW;
  45.    wc.lpfnWndProc   = (WNDPROC)WndProc;       
  46.    wc.cbClsExtra    = 0;                      
  47.    wc.cbWndExtra    = 0;                      
  48.    wc.hInstance     = hInstance;              
  49.    wc.hIcon         = LoadIcon (hInstance, lpszAppName); 
  50.    wc.hCursor       = LoadCursor(NULL, IDC_ARROW);
  51.    wc.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
  52.    wc.lpszMenuName  = lpszAppName;              
  53.    wc.lpszClassName = lpszAppName;              
  54.  
  55.    if ( IS_WIN95 )
  56.    {
  57.       if ( !RegisterWin95( &wc ) )
  58.          return( FALSE );
  59.    }
  60.    else if ( !RegisterClass( &wc ) )
  61.       return( FALSE );
  62.  
  63.    hInst = hInstance; 
  64.  
  65.    hWnd = CreateWindow( lpszAppName, 
  66.                         lpszTitle,    
  67.                         WS_OVERLAPPEDWINDOW, 
  68.                         CW_USEDEFAULT, 0, 
  69.                         CW_USEDEFAULT, 0,  
  70.                         NULL,              
  71.                         NULL,              
  72.                         hInstance,         
  73.                         NULL               
  74.                       );
  75.  
  76.    if ( !hWnd ) 
  77.       return( FALSE );
  78.  
  79.    ShowWindow( hWnd, nCmdShow ); 
  80.    UpdateWindow( hWnd );         
  81.  
  82.    while( GetMessage( &msg, NULL, 0, 0) )   
  83.    {
  84.       TranslateMessage( &msg ); 
  85.       DispatchMessage( &msg );  
  86.    }
  87.  
  88.    return( msg.wParam ); 
  89. }
  90.  
  91.  
  92. BOOL RegisterWin95( CONST WNDCLASS* lpwc )
  93. {
  94.     WNDCLASSEX wcex;
  95.  
  96.    wcex.style         = lpwc->style;
  97.    wcex.lpfnWndProc   = lpwc->lpfnWndProc;
  98.    wcex.cbClsExtra    = lpwc->cbClsExtra;
  99.    wcex.cbWndExtra    = lpwc->cbWndExtra;
  100.    wcex.hInstance     = lpwc->hInstance;
  101.    wcex.hIcon         = lpwc->hIcon;
  102.    wcex.hCursor       = lpwc->hCursor;
  103.    wcex.hbrBackground = lpwc->hbrBackground;
  104.    wcex.lpszMenuName  = lpwc->lpszMenuName;
  105.    wcex.lpszClassName = lpwc->lpszClassName;
  106.  
  107.    // Added elements for Windows 95.
  108.    //...............................
  109.    wcex.cbSize = sizeof(WNDCLASSEX);
  110.    wcex.hIconSm = LoadImage(wcex.hInstance, lpwc->lpszClassName, 
  111.                             IMAGE_ICON, 16, 16,
  112.                             LR_DEFAULTCOLOR );
  113.             
  114.    return RegisterClassEx( &wcex );
  115. }
  116.  
  117. typedef struct tagMYINFO    // general application information
  118. {
  119.    HPHONEAPP phoneApp;      // instance handle TAPI gives back to us                                                                              through phoneInitialize()
  120.    DWORD dwNumDevices;     // number of available devices
  121.    DWORD dwAPIVersion;     // API version the phone supports
  122.     DWORD dwExtVersion;        // extended version
  123. } MYINFO;
  124.  
  125. typedef struct tagPHONEINFO  // information on an open phone
  126. {
  127.    HPHONE     hPhone;           // handle to the phone as returned by phoneOpen 
  128.     DWORD      dwDeviceID;            // device ID of the phone device
  129.     DWORD        dwRequestID;
  130.     char       szPhoneName[128]; // the phone's name 
  131. }PHONEINFO;
  132.  
  133. MYINFO myInfo;          //instance of MYINFO structure
  134. PHONEINFO myPhoneInfo[MAX_PHONE];  //instance of myPhoneInfo structure
  135.  
  136. LONG lRet;        //return code
  137. char buf[BUFSIZE];    // buffer for debug message
  138. char DataBuf[BUFSIZE]; //get/set data buffer;
  139.  
  140. DWORD i;
  141. DWORD dwHookSwitchDevs;
  142. DWORD dwLampMode;
  143. DWORD dwRingMode;
  144. DWORD dwRingVolume;
  145. DWORD dwHookSwitchVolume;
  146. DWORD dwPhoneStates;
  147. DWORD dwButtonModes;
  148. DWORD dwButtonStates;
  149. DWORD dwGain;
  150. HICON hIcon;
  151.  
  152. LONG lRet;
  153. char buf[BUFSIZE];
  154.  
  155. PHONECAPS*             pPhoneCaps;
  156. PHONEBUTTONINFO*  pButtonInfo;
  157. VARSTRING*            pVarString;
  158. PHONESTATUS*        pPhoneStatus;
  159. PHONEEXTENSIONID    ext_id;                                             
  160.  
  161.  
  162. LRESULT CALLBACK WndProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam )
  163. {
  164.    switch( uMsg )
  165.    {
  166.       case WM_COMMAND :
  167.          switch( LOWORD( wParam ) )
  168.          {
  169.             case IDM_RUN  :
  170.                   pPhoneCaps = (PHONECAPS *) calloc (1, sizeof(PHONECAPS)+1000);
  171.                   pPhoneCaps->dwTotalSize = sizeof(PHONECAPS) + 1000;
  172.                   phoneGetDevCaps( myInfo.phoneApp, OWNER, myInfo.dwAPIVersion, 
  173.                                    myInfo.dwExtVersion, pPhoneCaps);
  174.                
  175.                   if (pPhoneCaps->dwGainFlags & PHONEHOOKSWITCHDEV_SPEAKER)
  176.                   {
  177.                      lRet = phoneGetGain(myPhoneInfo[OWNER].hPhone, PHONEHOOKSWITCHDEV_SPEAKER, &dwGain);
  178.                      if (lRet == 0)
  179.                      {
  180.                         wsprintf(buf, "phoneGetGain succeeded!");
  181.                         SendMessage(hListWnd, LB_INSERTSTRING, (WPARAM) -1, (LONG) (LPSTR) buf);
  182.                         wsprintf(buf, "The current gain is x%lx", dwGain);
  183.                         SendMessage(hListWnd, LB_INSERTSTRING, (WPARAM) -1, (LONG) (LPSTR) buf);
  184.                      }
  185.                      else 
  186.                      {
  187.                         wsprintf( buf,"phoneGetGain failed, err=x%lx", lRet);
  188.                         phoneError(lRet);
  189.                         break;
  190.                      }
  191.  
  192.                      if (dwGain < 0x0000CCCC)
  193.                      {
  194.                         wsprintf(buf, "The gain is less than 80%, setting gain!");
  195.                         SendMessage(hListWnd, LB_INSERTSTRING, (WPARAM) -1, (LONG) (LPSTR) buf);
  196.                         lRet = phoneSetGain( myPhoneInfo[OWNER].hPhone,
  197.                                              PHONEHOOKSWITCHDEV_SPEAKER, 0x0000CCCC);
  198.                         if (lRet > 0)
  199.                         {
  200.                            myPhoneInfo[OWNER].dwRequestID = lRet;
  201.                            wsprintf(buf, "phoneSetGain proceeding!");
  202.                            SendMessage(hListWnd, LB_INSERTSTRING, (WPARAM) -1, (LONG) (LPSTR) buf);
  203.                         }
  204.                         else 
  205.                         {
  206.                            wsprintf( buf,"phoneSetGain failed, err=x%lx", lRet);
  207.                            phoneError(lRet);
  208.                            SendMessage(hListWnd, LB_INSERTSTRING, (WPARAM) -1, (LONG) (LPSTR) buf);
  209.                         }    
  210.                      }
  211.                   }
  212.                   else
  213.                   {
  214.                      wsprintf( buf,"The phone does not have the capability to set the gain.");
  215.                      SendMessage(hListWnd, LB_INSERTSTRING, (WPARAM) -1, (LONG) (LPSTR) buf);
  216.                      phoneError(lRet);
  217.                   }
  218.                   free (pPhoneCaps);
  219.                   break;
  220.  
  221.             case IDM_EXIT :
  222.                   for (i = 0; i < myInfo.dwNumDevices; i++)
  223.                      phoneClose(myPhoneInfo[i].hPhone);
  224.                 
  225.                   phoneShutdown(myInfo.phoneApp);
  226.                   DestroyWindow( hWnd );
  227.                   break;
  228.  
  229.             case IDM_ABOUT :
  230.                   DialogBox( hInst, "AboutBox", hWnd, (DLGPROC)About );
  231.                   break;
  232.          }
  233.          return( DefWindowProc( hWnd, uMsg, wParam, lParam ) );
  234.  
  235.       
  236.        case WM_CREATE :
  237.  
  238.           hdc = GetDC (hWnd) ;
  239.           GetTextMetrics (hdc, &tm) ;
  240.           ReleaseDC (hWnd, hdc) ;
  241.  
  242.           hListWnd = CreateWindowEx( 0, "listbox", 
  243.                         " ",    
  244.                         WS_CHILD | WS_VISIBLE,  
  245.                         tm.tmAveCharWidth, tm.tmHeight * 3, 
  246.                         tm.tmAveCharWidth * 16 +
  247.                                    GetSystemMetrics (SM_CXVSCROLL), 
  248.                         tm.tmHeight * 5,  
  249.                         hWnd,              
  250.                         NULL,              
  251.                         hInst,         
  252.                         NULL               
  253.                         );
  254.       
  255.              //phoneInitialize
  256.                //...............................................
  257.             lRet = phoneInitialize(&myInfo.phoneApp, hInst, phoneCallback, lpszAppName, &myInfo.dwNumDevices);
  258.             if (lRet == 0) 
  259.             {
  260.                 
  261.                wsprintf(buf, "phoneInitialize succeeded!");
  262.                    SendMessage(hListWnd, LB_INSERTSTRING, (WPARAM) -1, (LONG) (LPSTR) buf) ;
  263.             }
  264.                
  265.                else 
  266.                {
  267.                    wsprintf( buf,"phoneInitialize failed, err=x%lx",lRet);
  268.                SendMessage(hListWnd, LB_INSERTSTRING, (WPARAM) -1, (LONG) (LPSTR) buf) ;
  269.                     phoneError(lRet);
  270.                     break;
  271.             }                    
  272.                
  273.             //phoneNegotiateAPIVersion
  274.                   //...............................................
  275.             lRet = phoneNegotiateAPIVersion(myInfo.phoneApp, 0, APILOWVERSION, APIHIVERSION, 
  276.                                                     &myInfo.dwAPIVersion, &ext_id);
  277.             if (lRet == 0)                        
  278.             {
  279.                wsprintf(buf, "phoneNegotiateAPIVersion succeeded!");
  280.                       SendMessage(hListWnd, LB_INSERTSTRING, (WPARAM) -1, (LONG) (LPSTR) buf) ;
  281.             }
  282.                   else 
  283.                   {
  284.                    wsprintf(buf, "phoneNegotiateAPIVersion failed, err=x%lx", lRet);
  285.                     SendMessage(hListWnd, LB_INSERTSTRING, (WPARAM) -1, (LONG) (LPSTR) buf) ;
  286.                     phoneError(lRet);
  287.                     phoneShutdown(myInfo.phoneApp);
  288.                break;
  289.              }
  290.  
  291.                //phoneNegotiateExtVersion
  292.                //...............................................
  293.             lRet = phoneNegotiateExtVersion(myInfo.phoneApp, 0, myInfo.dwAPIVersion, EXTLOWVERSION, 
  294.                                                 EXTHIVERSION, &myInfo.dwExtVersion);
  295.             if (lRet == 0)                        
  296.             {
  297.                     wsprintf(buf, "phoneNegotiateExtVersion succeeded!");
  298.                SendMessage(hListWnd, LB_INSERTSTRING, (WPARAM) -1, (LONG) (LPSTR) buf) ;
  299.               }
  300.                   else 
  301.                {
  302.                     wsprintf(buf, "phoneNegotiateExtVersion failed, err=x%lx", lRet);
  303.                       SendMessage(hListWnd, LB_INSERTSTRING, (WPARAM) -1, (LONG) (LPSTR) buf) ;
  304.                       phoneError(lRet);
  305.                }
  306.  
  307.             //phoneOpen
  308.                //................................................................
  309.                for (i = 0; i < myInfo.dwNumDevices; i++)
  310.                {
  311.                    if ( i == 0)
  312.                        lRet = phoneOpen(myInfo.phoneApp,i,&myPhoneInfo[i].hPhone,
  313.                                  myInfo.dwAPIVersion,0,(DWORD)phoneCallback, PHONEPRIVILEGE_OWNER);
  314.                    else
  315.                        lRet = phoneOpen(myInfo.phoneApp,i,&myPhoneInfo[i].hPhone,
  316.                                  myInfo.dwAPIVersion,0,(DWORD)phoneCallback, PHONEPRIVILEGE_MONITOR);
  317.                    
  318.                    if (lRet == 0)
  319.                    {
  320.                      wsprintf(buf, "phoneOpen succeeded!");
  321.                         SendMessage(hListWnd, LB_INSERTSTRING, (WPARAM) -1, (LONG) (LPSTR) buf) ;
  322.                   pPhoneCaps = (PHONECAPS *) calloc (1, sizeof(PHONECAPS)+1000);
  323.                       pPhoneCaps->dwTotalSize = sizeof(PHONECAPS) + 1000;
  324.                          
  325.                       phoneGetDevCaps(myInfo.phoneApp,i,
  326.                       myInfo.dwAPIVersion, myInfo.dwExtVersion, pPhoneCaps);
  327.                       strcpy(buf, ((LPSTR)(pPhoneCaps)+pPhoneCaps->dwProviderInfoOffset));
  328.                   strcat( buf, " is the phone providor's name." );
  329.                   SendMessage(hListWnd, LB_INSERTSTRING, (WPARAM) -1, (LONG) (LPSTR) buf) ;
  330.                   strcpy(buf, ((LPSTR)(pPhoneCaps)+pPhoneCaps->dwPhoneNameOffset));
  331.                      
  332.                   if (i == 0)
  333.                   {
  334.                      strcat( buf, " is the phone's name opened with OWNER privilege." );
  335.                      SendMessage(hListWnd, LB_INSERTSTRING, (WPARAM) -1, (LONG) (LPSTR) buf) ;
  336.                   }
  337.                   else
  338.                   {
  339.                      strcat( buf, " is the phone's name opened with MONITOR privilege." );
  340.                      SendMessage(hListWnd, LB_INSERTSTRING, (WPARAM) -1, (LONG) (LPSTR) buf) ;
  341.                   }
  342.                }
  343.                    else 
  344.                    {
  345.                        wsprintf( buf,"phoneOpen failed, err=x%lx", lRet);
  346.                        phoneError(lRet);
  347.                       break;
  348.                }
  349.                   } 
  350.  
  351.             break;
  352.       
  353.       case WM_SIZE:
  354.           MoveWindow(hListWnd,0, 0, LOWORD(lParam), HIWORD(lParam), TRUE);
  355.          break;
  356.  
  357.       case WM_DESTROY :
  358.          PostQuitMessage(0);
  359.          break;
  360.             
  361.       default :
  362.             return( DefWindowProc( hWnd, uMsg, wParam, lParam ) );
  363.    }
  364.  
  365.    return( 0L );
  366. }
  367.  
  368.  
  369.  
  370.  
  371. /****************************************************************************
  372.     FUNCTION: phoneCallback
  373.     PURPOSE:  callback function handles phone events
  374. ****************************************************************************/
  375. LRESULT CALLBACK phoneCallback (DWORD  dwDevice, DWORD dwMsg,
  376.                                 DWORD dwCallbackInst, DWORD dwParam1,
  377.                                 DWORD dwParam2,DWORD dwParam3)
  378. {
  379.     
  380.     switch (dwMsg)
  381.     {
  382.         case PHONE_REPLY:
  383.             if (dwParam1 == myPhoneInfo[OWNER].dwRequestID) 
  384.                    if (dwParam2 != 0)
  385.                 {
  386.                        wsprintf( buf,"Function failed, err=x%lx", lRet);
  387.                        phoneError(lRet);
  388.                     SendMessage(hListWnd, LB_INSERTSTRING, (WPARAM) -1, (LONG) (LPSTR) buf) ;
  389.                    }
  390.             break;       
  391.  
  392.         case PHONE_STATE:
  393.         
  394.             if (dwParam1 == PHONESTATE_RINGMODE)
  395.             {
  396.                 lRet = phoneGetRing(myPhoneInfo[OWNER].hPhone, &dwRingMode, &dwRingVolume);
  397.                 if (lRet == 0)
  398.                {
  399.                 wsprintf(buf, "phoneGetRing succeeded!");
  400.                    SendMessage(hListWnd, LB_INSERTSTRING, (WPARAM) -1, (LONG) (LPSTR) buf) ;
  401.                if (dwRingMode == 0)
  402.                     {
  403.                         wsprintf(buf, "The phone device is currently not ringing.");
  404.                         SendMessage(hListWnd, LB_INSERTSTRING, (WPARAM) -1, (LONG) (LPSTR) buf) ;
  405.                }
  406.                     else
  407.                     {
  408.                         wsprintf(buf, "The phone is ringing with a Ring Mode pattern of x%lx", dwRingMode);
  409.                         SendMessage(hListWnd, LB_INSERTSTRING, (WPARAM) -1, (LONG) (LPSTR) buf) ;
  410.                    wsprintf(buf, "The phnes's Ring Volume is x%lx", dwRingVolume);
  411.                         SendMessage(hListWnd, LB_INSERTSTRING, (WPARAM) -1, (LONG) (LPSTR) buf) ;
  412.                     }
  413.                }
  414.                  else 
  415.                {
  416.                     wsprintf( buf,"phoneGetRing failed, err=x%lx", lRet);
  417.                    phoneError(lRet);
  418.                }        
  419.               
  420.               break;
  421.               }
  422.             
  423.  
  424.             if (dwParam1 == PHONESTATE_SPEAKERHOOKSWITCH)
  425.             {   
  426.                 lRet = phoneGetHookSwitch(myPhoneInfo[OWNER].hPhone, &dwHookSwitchDevs);
  427.                 if (lRet == 0)
  428.                {
  429.                wsprintf(buf, "phoneGetHookSwitch succeeded!");
  430.                       SendMessage(hListWnd, LB_INSERTSTRING, (WPARAM) -1, (LONG) (LPSTR) buf) ;
  431.                
  432.                if (dwHookSwitchDevs & PHONEHOOKSWITCHDEV_SPEAKER)
  433.                     {
  434.                         wsprintf(buf, "The phone's HookSwitch Speaker is offhook!");
  435.                        SendMessage(hListWnd, LB_INSERTSTRING, (WPARAM) -1, (LONG) (LPSTR) buf) ;
  436.                     }
  437.                     else
  438.                     {
  439.                    wsprintf(buf, "The phone's HookSwitch Speaker is onhook!");
  440.                         SendMessage(hListWnd, LB_INSERTSTRING, (WPARAM) -1, (LONG) (LPSTR) buf) ;
  441.                     }
  442.  
  443.               }
  444.                  else 
  445.                {
  446.                       wsprintf( buf,"phoneGetHookSwitch failed, err=x%lx", lRet);
  447.                    phoneError(lRet);
  448.                }    
  449.             break;                
  450.             }
  451.  
  452.             if (dwParam1 == PHONESTATE_SPEAKERVOLUME)
  453.             {   
  454.                 lRet = phoneGetVolume(myPhoneInfo[OWNER].hPhone, PHONEHOOKSWITCHDEV_SPEAKER, &dwHookSwitchVolume);
  455.                if (lRet == 0)
  456.                {
  457.                 wsprintf(buf, "phoneGetVolume succeeded!");
  458.                    SendMessage(hListWnd, LB_INSERTSTRING, (WPARAM) -1, (LONG) (LPSTR) buf) ;
  459.                wsprintf(buf, "The current volume for the Speaker Hookswitch is x%lx", dwHookSwitchVolume);
  460.                     SendMessage(hListWnd, LB_INSERTSTRING, (WPARAM) -1, (LONG) (LPSTR) buf) ;
  461.                }
  462.                  else 
  463.                {
  464.                     wsprintf( buf,"phoneGetVolume failed, err=x%lx", lRet);
  465.                    phoneError(lRet);
  466.                }    
  467.             break;                
  468.             }
  469.  
  470.             if (dwParam1 == PHONESTATE_SPEAKERGAIN)
  471.             {   
  472.                 lRet = phoneGetGain(myPhoneInfo[OWNER].hPhone, PHONEHOOKSWITCHDEV_SPEAKER, &dwGain);
  473.                 if (lRet == 0)
  474.                {
  475.                   wsprintf(buf, "phoneGetGain succeeded!");
  476.                       SendMessage(hListWnd, LB_INSERTSTRING, (WPARAM) -1, (LONG) (LPSTR) buf) ;
  477.                     wsprintf(buf, "The current Gain is x%lx", dwGain);
  478.                     SendMessage(hListWnd, LB_INSERTSTRING, (WPARAM) -1, (LONG) (LPSTR) buf) ;
  479.                }
  480.                  else 
  481.                {
  482.                       wsprintf( buf,"phoneGetGain failed, err=x%lx", lRet);
  483.                     phoneError(lRet);
  484.                }
  485.             break;                
  486.             }
  487.             
  488.             if (dwParam1 == PHONESTATE_DISPLAY)
  489.             {   
  490.                 pVarString = (VARSTRING *) calloc (1, sizeof(VARSTRING)+1000);
  491.                 pVarString->dwTotalSize = sizeof(VARSTRING) + 1000;
  492.                 lRet = phoneGetDisplay(myPhoneInfo[OWNER].hPhone, pVarString);
  493.                 if (lRet == 0)
  494.                {
  495.                   wsprintf(buf, "phoneGetDisplay succeeded!");
  496.                       SendMessage(hListWnd, LB_INSERTSTRING, (WPARAM) -1, (LONG) (LPSTR) buf) ;
  497.                strcpy(buf, lpszTitle);
  498.                //strcpy(buf, ((LPSTR)(pVarString)+pVarString->dwStringOffset));
  499.                strcat( buf, " is the current phone display." );
  500.                SendMessage(hListWnd, LB_INSERTSTRING, (WPARAM) -1, (LONG) (LPSTR) buf) ;
  501.                }
  502.                  else 
  503.                {
  504.                    wsprintf( buf,"phoneGetDisplay failed, err=x%lx", lRet);
  505.                   phoneError(lRet);
  506.                }    
  507.                     
  508.                 free (pVarString);
  509.                 break;
  510.               }
  511.    }
  512.    return (TRUE);
  513.  
  514.  
  515. /****************************************************************************
  516.     FUNCTION: phoneError
  517.     PURPOSE:  phone error messages
  518. ****************************************************************************/
  519. void phoneError (LONG lrc)
  520. {
  521.  switch (lrc) {
  522.     case PHONEERR_INVALAPPHANDLE:
  523.        MessageBox (hWnd, "Invalid app handle.", "", MB_OK);
  524.        break;
  525.     case PHONEERR_BADDEVICEID:
  526.        MessageBox (hWnd,"The specified phone device ID is out of range.", "", 
  527.                    MB_OK);
  528.        break;
  529.     case PHONEERR_INCOMPATIBLEAPIVERSION:
  530.        MessageBox (hWnd, "Incompatible API version.", "", MB_OK);
  531.        break;
  532.     
  533.     case PHONEERR_INVALBUTTONLAMPID:
  534.        MessageBox (hWnd, "Invalid Button Lamp ID.", "", MB_OK);
  535.        break;
  536.  
  537.     case PHONEERR_INVALBUTTONMODE:
  538.        MessageBox (hWnd, "Invalid Button Mode.", "", MB_OK);
  539.        break;
  540.  
  541.     case PHONEERR_INVALBUTTONSTATE:
  542.        MessageBox (hWnd, "Invalid Button State", "", MB_OK);
  543.        break;
  544.  
  545.     case PHONEERR_INUSE:
  546.        MessageBox (hWnd, "Phone in Use.", "", MB_OK);
  547.        break;
  548.     
  549.     case PHONEERR_INVALHOOKSWITCHDEV:
  550.        MessageBox (hWnd, "Invalid Hookswitch Device.", "", MB_OK);
  551.        break;
  552.  
  553.     case PHONEERR_INVALHOOKSWITCHMODE:
  554.        MessageBox (hWnd, "Invalid Hookswitch Device Mode.", "", MB_OK);
  555.        break;
  556.  
  557.     case PHONEERR_INVALLAMPMODE:
  558.        MessageBox (hWnd, "Invalid Lamp Mode.", "", MB_OK);
  559.        break;
  560.      
  561.     case PHONEERR_INCOMPATIBLEEXTVERSION:
  562.        MessageBox (hWnd, "Incompatible extension version.","", MB_OK);
  563.        break;
  564.     case PHONEERR_NOMEM:
  565.        MessageBox (hWnd, "No memory","", MB_OK);
  566.        break;
  567.     case PHONEERR_NODRIVER:
  568.        MessageBox (hWnd, "No driver loaded", "", MB_OK);
  569.        break;
  570.     case PHONEERR_RESOURCEUNAVAIL:
  571.        MessageBox (hWnd, "Resource overcommittment", "", MB_OK);
  572.        break;
  573.     case PHONEERR_ALLOCATED:
  574.        MessageBox (hWnd, "Allocation error", "", MB_OK);
  575.        break;
  576.     case PHONEERR_INVALDATAID:
  577.        MessageBox (hWnd, "The data ID is out of range.", "", MB_OK);
  578.        break;
  579.     case PHONEERR_INVALDEVICECLASS:
  580.        MessageBox (hWnd, "The device class was invalid.", "", MB_OK);
  581.        break;
  582.     case PHONEERR_INVALPOINTER:
  583.        MessageBox (hWnd, "The specified pointer parameter is invalid.",
  584.                    "", MB_OK);
  585.        break;
  586.     case PHONEERR_OPERATIONFAILED:
  587.        MessageBox (hWnd, "Operation failed.", "", MB_OK);
  588.        break;
  589.     case PHONEERR_INVALPHONEHANDLE:
  590.        MessageBox (hWnd, "Invalid phone handle", "", MB_OK);
  591.        break;
  592.     case PHONEERR_INVALPHONESTATE :
  593.        MessageBox (hWnd, "Invalid call state for this function.", "", MB_OK);
  594.        break;
  595.     case PHONEERR_INVALPRIVILEGE:
  596.        MessageBox (hWnd, "Invalid privilege for this function.", "", MB_OK);
  597.        break;
  598.     case PHONEERR_NODEVICE:
  599.        MessageBox (hWnd, "No associated device for given class",
  600.                    "", MB_OK);
  601.        break;
  602.     case PHONEERR_OPERATIONUNAVAIL:
  603.        MessageBox (hWnd, "The operation is unavailable",
  604.                    "", MB_OK);
  605.        break;
  606.     case PHONEERR_INVALPARAM:
  607.         MessageBox(hWnd, "Invalid Paramater", "", MB_OK);
  608.        break; 
  609.  
  610.     case PHONEERR_INVALRINGMODE:
  611.             MessageBox(hWnd, "Invalid Ring Mode", "", MB_OK);
  612.        break; 
  613.  
  614.     }
  615.     
  616.              
  617. }
  618.  
  619. LRESULT CALLBACK About( HWND hDlg,           
  620.                         UINT message,        
  621.                         WPARAM wParam,       
  622.                         LPARAM lParam)
  623. {
  624.    switch (message) 
  625.    {
  626.        case WM_INITDIALOG: 
  627.                return (TRUE);
  628.  
  629.        case WM_COMMAND:                              
  630.                if (   LOWORD(wParam) == IDOK         
  631.                    || LOWORD(wParam) == IDCANCEL)    
  632.                {
  633.                        EndDialog(hDlg, TRUE);        
  634.                        return (TRUE);
  635.                }
  636.                break;
  637.    }
  638.  
  639.    return (FALSE); 
  640. }
  641.  
  642.  
  643.  
  644.  
  645.  
  646.  
  647.